import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import UnoCss from 'unocss/vite'
import { ConfigEnv, defineConfig, loadEnv, UserConfigExport } from 'vite'

export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  const root: string = process.cwd()
  const env = loadEnv(mode, root)
  const isProd = mode === 'production'
  const isBuild = command === 'build'

  const { VITE_API_ENDPOINT, VITE_PROXY_TARGET, VITE_BUILD_DIR } = env
  return defineConfig({
    plugins: [vueJsx(), vue(), UnoCss()],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    server: {
      port: 8080,
      proxy: {
        '/dev': {
          target: VITE_PROXY_TARGET,
          secure: false,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev/, '')
        },
        '/image': {
          target: 'http://training.k8slab.cn/image',
          secure: false,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/image/, '')
        },
        '/comments': {
          target: 'https://austug922h.execute-api.cn-northwest-1.amazonaws.com.cn',
          secure: false,
          changeOrigin: true
        },
        '/HPImageArchive.aspx': {
          target: 'https://www.bing.com/',
          changeOrigin: true
        },
        // '^/dockerapi-191': {
        //   target: 'http://172.16.90.159/',
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/dockerapi-191/, ''),
        // },
        '^/dockerapi-(.*)': {
          target: 'http://172.16.90.159/',
          changeOrigin: true,
          
        },
        '^/container-(.*)': {
          target: 'http://172.16.90.159/',
          changeOrigin: true,
          ws: true
        }
    
      }
    }
  })
}
